package com.magenta.maxoptra.gis.distancematrix.commands;

import com.magenta.maxoptra.gis.distancematrix.CommandType;
import com.magenta.maxoptra.gis.distancematrix.DistanceMatrixDAO;
import com.magenta.maxoptra.gis.distancematrix.DistanceMatrixServiceProxy;
import com.magenta.maxoptra.gis.distancematrix.UpdateRequestType;

/**
 * @author Sergey Grachev
 */
final class ChangeRequestsDelay extends AbstractGroupCommand {

    private final int delay;

    ChangeRequestsDelay(final long groupId, final int delay) {
        super(groupId);
        this.delay = delay;
    }

    @Override
    public CommandType getType() {
        return CommandType.CHANGE_REQUESTS_INTERVAL;
    }

    @Override
    public void execute(final DistanceMatrixDAO db, final DistanceMatrixServiceProxy service) {
        groupContext.setRequestsDelay(delay);
        service.changeRequestsDelay(groupContext.getId(), delay);
    }

    @Override
    public UpdateRequestType isRequireMatrixUpdating() {
        return UpdateRequestType.NONE;
    }

    @Override
    public boolean isRequireGroupLock() {
        return false;
    }

    @Override
    public String toString() {
        return "ChangeRequestsDelay{" +
                "groupId=" + groupId +
                ", delay=" + delay +
                '}';
    }
}
